import os
from conan import ConanFile
from conan.tools.files import copy
from conan.tools.cmake import cmake_layout


class JsonTestRecipe(ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    generators =   "CMakeDeps","CMakeToolchain"

    #设置`shared`属性可以为[True,False]
    options ={"shared":[True, False]}
    #options中的属性设置默认值
    default_options = {"shared": True}

    def requirements(self):
        self.requires("jsoncpp/1.9.6")

    def layout(self):
        cmake_layout(self)

    def build_requirements(self):
        self.tool_requires("cmake/3.22.6")

    def generate(self):
        #如果采用动态库的方式
        #将动态库复制到可执行文件目录下
        if not self.options.shared:
            return
        for dep in self.dependencies.values():
            for depDll in dep.cpp_info.bindirs:
                print(">>>self.source_folder: ", self.source_folder)
                print(">>>")
                print(">>>", depDll)
                print(">>>")

                # 使用 msvc 编译时，需要将动态库复制到可执行文件目录下
                copy(self,"*.dll", depDll,
                     os.path.join(self.source_folder, "build/Release"))

                # # 使用 gcc 编译时，需要将动态库复制到可执行文件目录下
                copy(self,"*.dll", depDll,
                     os.path.join(self.source_folder, "build"))


